package com.atguigu.gulimail.ware.service.impl;

import com.alibaba.cloud.commons.lang.StringUtils;
import com.atguigu.gulimail.ware.entity.WmsPurchaseDetailEntity;
import org.springframework.stereotype.Service;

import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.Query;

import com.atguigu.gulimail.ware.dao.WmsPurchaseDetailDao;
import com.atguigu.gulimail.ware.entity.WmsPurchaseDetailEntity;
import com.atguigu.gulimail.ware.service.WmsPurchaseDetailService;


@Service("wmsPurchaseDetailService")
public class WmsPurchaseDetailServiceImpl extends ServiceImpl<WmsPurchaseDetailDao,
        WmsPurchaseDetailEntity> implements WmsPurchaseDetailService {


    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        final QueryWrapper<WmsPurchaseDetailEntity> wrapper = new QueryWrapper<>();
        final IPage<WmsPurchaseDetailEntity> page1 =
                new Query<WmsPurchaseDetailEntity>().getPage(params);

        String key = (String) params.get("key");
        if (!StringUtils.isBlank(key)) {
            wrapper.and(w -> w.eq("purchase_id", key).or().eq("sku_id", key));
        }

        String statusStr = (String) params.get("status");
        if (!StringUtils.isBlank(statusStr)) {
            wrapper.eq("status", statusStr);
        }
        final String wareIdStr = (String) params.get("wareId");
        if (!StringUtils.isBlank(wareIdStr)) {
            long wareId = Long.parseLong(wareIdStr);
            if (wareId > 0) {
                wrapper.eq("ware_id", wareId);
            }
        }
        IPage<WmsPurchaseDetailEntity> page = this.page(page1, wrapper);
        return new PageUtils(page);
    }

}